using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace BlogKickStart.Models.Mapping
{
    public class PostMap : EntityTypeConfiguration<Post>
    {
        public PostMap()
        {
            // Primary Key
            this.HasKey(t => t.PostID);

            // Properties
            this.Property(t => t.Title)
                .HasMaxLength(256);

            // Table & Column Mappings
            this.ToTable("Posts");
            this.Property(t => t.PostID).HasColumnName("PostID");
            this.Property(t => t.BlogID).HasColumnName("BlogID");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.UnmarkedContent).HasColumnName("UnmarkedContent");
            this.Property(t => t.MarkedContent).HasColumnName("MarkedContent");
            this.Property(t => t.Date).HasColumnName("Date");
            this.Property(t => t.Active).HasColumnName("Active");

            // Relationships
            this.HasRequired(t => t.Blog)
                .WithMany(t => t.Posts)
                .HasForeignKey(d => d.BlogID);

        }
    }
}
